package com.wc.alorithm_luogu._简单题.DlgtPattern;

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/11/10 14:31
 * @description
 * https://www.luogu.com.cn/problem/T474063?contestId=127930
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static int x, y, p, q;

    public static void main(String[] args) {
        x = sc.nextInt();
        y = sc.nextInt();
        p = sc.nextInt();
        q = sc.nextInt();
        int res = Math.min(Math.min(p, q), Math.min(x - p, y - q));
        out.println(res);
        out.flush();
    }
}


